﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Freedom.Models.ViewModels;
using Freedom.Models.Interfaces;
using Freedom.Models.Services;
using Freedom.Models;
using MvcPaging;

namespace Freedom.Controllers
{
    /// <summary>
    /// 案例控制器
    /// autor: Penn Yao
    /// </summary>
    [HandleError]
    public class PortfolioController : Controller
    {
        PortfolioViewModel viewModel;
        IPortfolioClassService portfolioClassService;
        IPortfolioInfoService portfolioInfoService;

        public PortfolioController()
        {
            if (viewModel == null)
                viewModel = new PortfolioViewModel();
            if (portfolioClassService == null)
                portfolioClassService = new PortfolioClassService();
            if (portfolioInfoService == null)
                portfolioInfoService = new PortfolioInfoService();
        }

        public ActionResult Index(int? page)
        {
            List<tb_PortfolioClass> portfolioClassList = null;
            if (portfolioClassService != null)
                portfolioClassList = portfolioClassService.getAllClass().ToList();

            List<tb_PortfolioInfo> portfolioInfoList = null;
            if (portfolioInfoService != null)
                portfolioInfoList = portfolioInfoService.getAllInfo().ToList();

            IPagedList<tb_PortfolioInfo> portfolioInfoPagedList = null;
            if (portfolioInfoService != null)
                portfolioInfoPagedList = portfolioInfoService.getAllPagedInfo().ToPagedList(page.HasValue ? page.Value - 1 : 0, 2);

            if (viewModel != null)
            {
                viewModel.portfolioClassList = portfolioClassList;
                viewModel.portfolioInfoList = portfolioInfoList;
                viewModel.portfolioInfoPagedList = portfolioInfoPagedList;
            }

            return View(viewModel);
        }

        public ActionResult Single()
        {
            return View(viewModel);
        }
    }
}
